<?xml version="1.0" encoding="utf-8"?>
<grammar xmlns="http://relaxng.org/ns/structure/1.0" xmlns:hr="http://eric.van-der-vlist.com/ns/person" ns="http://eric.van-der-vlist.com/ns/library">
  <start>
    <element name="library">
      <oneOrMore>
        <ref name="book-element"/>
      </oneOrMore>
    </element>
  </start>
  <define name="anything">
    <zeroOrMore>
      <choice>
        <element>
          <anyName/>
          <ref name="anything"/>
        </element>
        <attribute>
          <anyName/>
        </attribute>
        <text/>
      </choice>
    </zeroOrMore>
  </define>
  <define name="foreign-elements">
    <zeroOrMore>
      <element>
        <anyName>
          <except>
            <nsName ns=""/>
            <nsName ns="http://eric.van-der-vlist.com/ns/library"/>
            <nsName ns="http://eric.van-der-vlist.com/ns/person"/>
          </except>
        </anyName>
        <ref name="anything"/>
      </element>
    </zeroOrMore>
  </define>
  <define name="foreign-attributes">
    <zeroOrMore>
      <attribute>
        <anyName>
          <except>
            <nsName ns=""/>
            <nsName ns="http://eric.van-der-vlist.com/ns/library"/>
            <nsName ns="http://eric.van-der-vlist.com/ns/person"/>
          </except>
        </anyName>
      </attribute>
    </zeroOrMore>
  </define>
  <define name="foreign-nodes">
    <zeroOrMore>
      <choice>
        <ref name="foreign-attributes"/>
        <ref name="foreign-elements"/>
      </choice>
    </zeroOrMore>
  </define>
  <define name="author-element">
    <element name="hr:author">
      <attribute name="id"/>
      <ref name="name-element"/>
      <ref name="born-element"/>
      <optional>
        <ref name="dead-element"/>
      </optional>
    </element>
  </define>
  <define name="book-element">
    <element name="book">
      <interleave>
        <group>
          <attribute name="id"/>
          <attribute name="available"/>
          <ref name="isbn-element"/>
          <ref name="title-element"/>
          <zeroOrMore>
            <ref name="author-element"/>
          </zeroOrMore>
          <zeroOrMore>
            <ref name="character-element"/>
          </zeroOrMore>
        </group>
        <ref name="foreign-nodes"/>
      </interleave>
    </element>
  </define>
  <define name="born-element">
    <element name="hr:born">
      <text/>
    </element>
  </define>
  <define name="character-element">
    <element name="character">
      <attribute name="id"/>
      <ref name="name-element"/>
      <ref name="born-element"/>
      <ref name="qualification-element"/>
    </element>
  </define>
  <define name="dead-element">
    <element name="hr:dead">
      <text/>
    </element>
  </define>
  <define name="isbn-element">
    <element name="isbn">
      <ref name="foreign-attributes"/>
      <text/>
    </element>
  </define>
  <define name="name-element">
    <element name="hr:name">
      <text/>
    </element>
  </define>
  <define name="qualification-element">
    <element name="qualification">
      <text/>
    </element>
  </define>
  <define name="title-element">
    <element name="title">
      <ref name="foreign-attributes"/>
      <text/>
    </element>
  </define>
</grammar>
